package zyq.dao;

import org.springframework.stereotype.Repository;
import zyq.po.Student;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

@Repository(value = "userDaoImpl")
public class UserDaoImpl {

    public static void main(String[] args) throws ClassNotFoundException {
        System.out.println(Class.forName("com.mysql.cj.jdbc.Driver"));
    }

    public boolean login(Student stu) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&serverTimezone=GMT%2B8",
                "root","root");
        //预编译sql
        PreparedStatement pstmt = conn.prepareStatement("select userPass from student where userName = ?");
        pstmt.setString(1,stu.getStuName());
        ResultSet rs=pstmt.executeQuery();// 查询结果集
        if (rs.next()) {
            // mysql密码和jsp密码相匹配
            if (rs.getString("userPass").equals(stu.getStuPwd())) {
                return true;
            }else{
                return false;
            }
        }else {
            return false;
        }
    }

}